#include<iostream>
using namespace std;

class Solution {
public:
    double myPow(double x, int n) {
        return n < 0 ? 1.0 / dfs(x, n) : dfs(x, n);
    }

    double dfs(double x, int n)
    {
        if (n == 0) return 1;

        double ret = dfs(x, n / 2);
        return n % 2 == 0 ? ret * ret : ret * ret * x;
    }
};